package com.fzu.ess.ess.entity;

import com.fzu.ess.common.entity.BaseEntity;

import com.fzu.ess.sys.entity.User;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by ercha on 2015/10/24.
 */
@Entity
@Data
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name="ess_book")
public class Book extends BaseEntity {
    public Book(){ super(); }

    public Book(String id){
        super();
        this.id = id;
    }

    @Column(name="cover")
    private String cover;       //封面 url

//    @Column(name="thumbnail")
//    private String thumbnail;   //缩略图 url

    @Column(name="name")
    private String name;        //书名

    @ElementCollection
    @CollectionTable(name="ess_image",
            joinColumns=@JoinColumn(name="one_id", nullable = false))
    @Column(name="url")
    @OrderColumn(name="list_order") //不可以使用 index 作为 name，似乎是因为是关键字。。
    private List<String> imageList = new ArrayList<>(); //展示图片 url

//    @OneToMany
//    @JoinTable(name = "ess_image_intermediate",
//    joinColumns = @JoinColumn(name = "one_id", referencedColumnName = "id"),
//    inverseJoinColumns = @JoinColumn(name = "image_id", referencedColumnName = "id", unique = true))
//    private Set<String> imageList = new HashSet<>();     //展示图片

    @Column(name="isbn")
    private String isbn;           //isbn

    @Column(name="author")
    private String author;          //书籍作者

    @ManyToOne
    @JoinColumn(name="language")
    private Language bookLanguage;       //语言

    @Column(name="publishing_house")
    private String publishingHouse; //出版社

    @Column(name="publication_year")
    private String publicationYear; //出版年份

    @Column(name="price")
    private Float price;            //价格

    @Column(name="remark")
    private String remark;          //书籍拥有者备注

    /**
     * 0: 下架
     * 1: 上架
     */
    @Column(name="status")
    private Integer status;

    @ManyToOne
    @JoinColumn(name="owner_id")
    private User owner;         //拥有者

}
